import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

import Studemo1 from '../views/study1/StuDemo1.vue'
import StuDemo1fx from '../views/study1/StuDemo1fx.vue'

import StuDemo2 from '../views/study1/StuDemo2.vue'

import StuDemo2fx from '../views/study1/StuDemo2fx.vue'

import StuDemo3 from '../views/study1/StuDemo3.vue'
import StuDemo4 from '../views/study1/StuDemo4'
import StuDemo5 from '../views/study1/StuDemo5.vue'
import StuDemo6 from '../views/study1/StuDemo6.vue'

import StuDemo21 from '../views/study2/StuDemo1.vue'
import StuDemo22 from '../views/study2/StuDemo2.vue'
import StuDemo23 from '../views/study2/StuDemo3.vue'
import StuDemo24 from '../views/study2/StuDemo4.vue'
import StuDemo25 from '../views/study2/StuDemo5.vue'

import StuDemo31 from '../views/study3/StuDemo1.vue'
import StuDemo32 from '../views/study3/StuDemo2.vue'
import StuDemo33 from '../views/study3/StuDemo3.vue'
import StuDemo34 from '../views/study3/StuDemo4.vue'
import StuDemo35 from '../views/study3/StuDemo5.vue'
import StuDemo36 from '../views/study3/StuDemo6.vue'
import StuDemo37 from '../views/study3/StuDemo7.vue'
import StuDemo38 from '../views/study3/StuDemo8.vue'
import StuDemo39 from '../views/study3/StuDemo9.vue'
import StuDemo310 from '../views/study3/StuDemo10.vue'
import StuDemo311 from '../views/study3/StuDemo11.vue'
import StuDemo312 from '../views/study3/StuDemo12.vue'
import StuDemo313 from '../views/study3/StuDemo13.vue'
import StuDemo314 from '../views/study3/StuDemo14.vue'
import StuDemo315 from '../views/study3/StuDemo15.vue'
import StuDemo316 from '../views/study3/StuDemo16.vue'
import StuDemo317 from '../views/study3/StuDemo17.vue'

// study4
import StuDemo41 from '../views/study4/StuDemo1.vue'
import StuDemo42 from '../views/study4/StuDemo2.vue'
import StuDemo43 from '../views/study4/StuDemo3.vue'
import StuDemo44 from '../views/study4/StuDemo4.vue'
import StuDemo45 from '../views/study4/StuDemo5.vue'
import StuDemo46 from '../views/study4/StuDemo6.vue'
import StuDemo47 from '../views/study4/StuDemo7.vue'
import StuDemo48 from '../views/study4/StuDemo8.vue'

// study5
import StuDemo51 from '../views/study5/StudyDemo1.vue'
import StuDemo52 from '../views/study5/StudyDemo2.vue'

// study6
import StuDemo61 from '../views/study6/Demo1.vue'
import StuDemo62 from '../views/study6/Demo2.vue'
import StuDemo611 from '../views/study6/NavigatorOne/Option1.vue'
import StuDemo612 from '../views/study6/NavigatorOne/Option2.vue'
import StuLogin6 from '../views/study6/Login.vue'

// studyDemo
import StduyDemo1 from '../views/studydemo/demo1.vue'
import StduyDemo2 from '../views/studydemo/demo2.vue'
import StduyDemo3 from '../views/studydemo/demo3.vue'
import StduyDemo4 from '../views/studydemo/demo4.vue'
import StduyDemo5 from '../views/studydemo/demo5.vue'

// mytest
import Mytest1 from '../views/mytest/test1.vue'

// studyrouter
import srDemo1 from '../views/studyrouter/demo1.vue'

// studyrouter-children
import srDetail1 from '../views/studyrouter/sdchildren/detail1.vue'
import srDetail2 from '../views/studyrouter/sdchildren/detail2.vue'
import srDetail3 from '../views/studyrouter/sdchildren/detail3.vue'

const studyRouter = [
  {
    name: 'srdemo1',
    path: '/srdemo1',
    component: srDemo1,
    title: '嵌套路由',
    // redirect: '/', 重定向
    children: [
      {
        name: 'xiang1',
        path: 'detail1',
        component: srDetail1
      },
      {
        name: 'xiang2',
        path: 'detail2/:title/:content',
        component: srDetail2,
        props: true
      },
      {
        name: 'defaultp',
        path: 'user/:id',
        components: { default: srDetail1, sidebar: srDetail2 },
        props: { default: true, sidebar: false }
      },
      {
        name: 'xiang3',
        path: 'detail3',
        component: srDetail3
      }
    ]
  }
]

// study1
const study1Routers = [
  {
    path: '/studemo1',
    name: 'studemo1',
    component: Studemo1
  },
  {
    path: '/studemo1fx',
    name: 'studemo1fx',
    component: StuDemo1fx
  },
  {
    path: '/StuDemo2fx',
    name: 'StuDemo2fx',
    component: StuDemo2fx
  },
  {
    path: '/studemo2',
    name: 'studemo2',
    component: StuDemo2
  },

  {
    path: '/studemo3',
    name: 'studemo3Name',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: StuDemo3
  },
  {
    path: '/studemo4',
    name: 'studemo4',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: StuDemo4
  },
  {
    path: '/studemo5',
    name: 'studemo5',
    component: StuDemo5
  },
  {
    path: '/studemo6',
    name: 'studemo6',
    component: StuDemo6
  }
]

// study2
const study2Routers = [
  {
    path: '/studemo21',
    name: 'studemo21',
    component: StuDemo21
  },
  {
    path: '/studemo22',
    name: 'studemo22',
    component: StuDemo22
  },
  {
    path: '/studemo23',
    name: 'studemo23',
    component: StuDemo23
  },
  {
    path: '/studemo24',
    name: 'studemo24',
    component: StuDemo24
  },
  {
    path: '/studemo25',
    name: 'studemo25',
    component: StuDemo25
  }
]

// study3
const study3Routers = [
  {
    path: '/studemo31',
    name: 'studemo31',
    component: StuDemo31
  },
  {
    path: '/studemo32',
    name: 'studemo32',
    component: StuDemo32
  },
  {
    path: '/studemo33',
    name: 'studemo33',
    component: StuDemo33
  },
  {
    path: '/studemo34',
    name: 'studemo34',
    component: StuDemo34
  },
  {
    path: '/studemo35',
    name: 'studemo35',
    component: StuDemo35
  },
  {
    path: '/studemo36',
    name: 'studemo36',
    component: StuDemo36
  },
  {
    path: '/studemo37',
    name: 'studemo37',
    component: StuDemo37
  },
  {
    path: '/studemo38',
    name: 'studemo38',
    component: StuDemo38
  },
  {
    path: '/studemo39',
    name: 'studemo39',
    component: StuDemo39
  },
  {
    path: '/studemo310',
    name: 'studemo310',
    component: StuDemo310
  },
  {
    path: '/studemo311',
    name: 'studemo311',
    component: StuDemo311
  },
  {
    path: '/studemo312',
    name: 'studemo312',
    component: StuDemo312
  },
  {
    path: '/studemo313',
    name: 'studemo313',
    component: StuDemo313
  },
  {
    path: '/studemo314',
    name: 'studemo314',
    component: StuDemo314
  },
  {
    path: '/studemo315',
    name: 'studemo315',
    component: StuDemo315
  },
  {
    path: '/studemo316',
    name: 'studemo316',
    component: StuDemo316
  },
  {
    path: '/studemo317',
    name: 'studemo317',
    component: StuDemo317
  }
]

// study4
const study4Routers = [
  {
    path: '/studemo41',
    name: 'studemo41',
    component: StuDemo41
  },
  {
    path: '/studemo42',
    name: 'studemo42',
    component: StuDemo42
  },
  {
    path: '/studemo43',
    name: 'studemo43',
    component: StuDemo43
  },
  {
    path: '/studemo44',
    name: 'studemo44',
    component: StuDemo44
  },
  {
    path: '/studemo45',
    name: 'studemo45',
    component: StuDemo45
  },
  {
    path: '/studemo46',
    name: 'studemo46',
    component: StuDemo46
  },
  {
    path: '/studemo47',
    name: 'studemo47',
    component: StuDemo47
  },
  {
    path: '/studemo48',
    name: 'studemo48',
    component: StuDemo48
  }
]

// study5
const study5Routers = [
  {
    path: '/studemo51',
    name: 'studemo51',
    component: StuDemo51
  },
  {
    path: '/studemo52',
    name: 'studemo52',
    component: StuDemo52
  }
]

// study6
const study6Routers = [
  {
    path: '/login',
    name: 'login',
    component: StuLogin6,
    meta: { title: 'StuLogin6' }
  },
  {
    path: '/studemo61',
    name: 'studemo61',
    component: StuDemo61,
    meta: { title: 'StuDemo61' }
  },
  {
    path: '/studemo62',
    name: 'studemo62',
    component: StuDemo62,
    meta: { title: '系统管理' },
    children: [
      {
        name: 'userManage',
        path: 'user',
        component: StuDemo611,
        meta: { title: '用户管理' }
      },
      {
        name: 'roleManage',
        path: 'role',
        component: StuDemo612,
        meta: { title: '角色管理' }
      }
    ]
  }
]

// studyDemo
const studyDemoRouters = [
  {
    path: '/stduydemo1',
    name: 'stduydemo1',
    component: StduyDemo1
  },
  {
    path: '/stduydemo2',
    name: 'stduydemo2',
    component: StduyDemo2
  },
  {
    path: '/stduydemo3',
    name: 'stduydemo3',
    component: StduyDemo3
  },
  {
    path: '/stduydemo4',
    name: 'stduydemo4',
    component: StduyDemo4
  },
  {
    path: '/stduydemo5',
    name: 'stduydemo5',
    component: StduyDemo5
  }
]

// study4
const testDemo = [
  {
    path: '/mytest1',
    name: 'mytest1',
    component: Mytest1
  }
]

export const routesList = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: { title: '首页' }
  },
  ...study6Routers,
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (About.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import('../views/AboutView.vue')
  // },
  ...study1Routers,
  ...study2Routers,
  ...study3Routers,
  ...study4Routers,
  ...study5Routers,
  ...studyDemoRouters,
  ...testDemo,
  ...studyRouter
]

const router = createRouter({
  // history:createWebHistory(), //history模式
  history: createWebHashHistory(), //hash模式
  routes: routesList
})

// router.beforeEach((to, from, next) => {

//   const token = localStorage.getItem('token')

//   if (token) {
//     // 如果登陆正常放过

//     if (to.path === '/login') {
//       next('/studemo62/user')
//     } else {
//       next()
//     }

//   } else {

//     // 如果没有登陆 且 目标页面是登录页
//     if (to.path === '/login') {
//       next()
//     } else {
//       // 目标路由不是login 跳转到login
//       next('/login')
//     }

//   }

// })

export default router
